<extend name="public@base5"/>
<block name="main">
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link active" href="{:url('Plugin/index')}">{:lang('ADMIN_PLUGIN_INDEX')}</a>
            </li>
            <if condition="class_exists('\app\admin\controller\AppStoreController')">
                <li class="nav-item">
                    <a class="nav-link" href="{:url('AppStore/plugins')}">{:lang('ADMIN_APPSTORE_PLUGINS')}</a>
                </li>
            </if>
            <li class="nav-item">
                <a class="nav-link"
                   href="http://www.thinkcmf.com/faq.html?url=https://www.kancloud.cn/thinkcmf/faq/493510"
                   target="_blank">{:lang('Plugin offline installation')}<i class="fa fa-question-circle"></i>
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="http://www.thinkcmf.com/topic/index/index/cat/9.html"
                   target="_blank">{:lang('Plugin discussion')}</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="https://www.thinkcmf.com/docs/cmf8/#/%E6%8F%92%E4%BB%B6"
                   target="_blank">{:lang('Plugin doc')}</a>
            </li>
        </ul>
        <form method="post" class="js-ajax-form margin-top-20">
            <php>
                $status=array("1"=>lang('ENABLED'),"0"=>lang('DISABLED'),"3"=>lang('Not Installed'));
            </php>
            <table class="table table-hover table-bordered">
                <thead>
                <tr>
                    <th>{:lang('Name')}</th>
                    <th>{:lang('Key')}</th>
                    <th>{:lang('Description')}</th>
                    <th>{:lang('Author')}</th>
                    <th>{:lang('Version')}</th>
                    <th width="60">{:lang('Status')}</th>
                    <th width="180">{:lang('ACTIONS')}</th>
                </tr>
                </thead>
                <tbody>
                <foreach name="plugins" item="vo">
                    <tr>
                        <td>{$vo.title}</td>
                        <td><span class="badge text-bg-info">{$vo.name}</span></td>
                        <td>{$vo.description}</td>
                        <td>{$vo.author}</td>
                        <td><span class="badge text-bg-success">{$vo.version}</span></td>
                        <td>
                            <switch name="vo.status">
                                <case value="0">
                                <span class="badge text-bg-warning">
                                    {$status[$vo['status']]}
                                </span>
                                </case>
                                <case value="1">
                                <span class="badge text-bg-success">
                                    {$status[$vo['status']]}
                                </span>
                                </case>
                                <case value="3">
                                <span class="badge text-bg-info">
                                    {$status[$vo['status']]}
                                </span>
                                </case>
                            </switch>
                        </td>
                        <td>
                            <if condition="$vo['status']==3">
                                <a class="btn btn-xs btn-primary js-ajax-dialog-btn"
                                   href="javascript:void(0);"
                                   data-href="admin/plugins/{$vo.name}"
                                   data-msg="{:lang('INSTALL_PLUGIN_CONFIRM_MSG')}"
                                   title="{:lang('Install')}" data-toggle="tooltip">
                                    <i class="fa fa-plus-circle fa-fw"></i></a>
                                <else/>
                                <php>$config=$vo['config'];</php>
                                <if condition="!empty($vo['has_admin']) && $vo['status']==1">
                                    <a class="btn btn-xs btn-info"
                                       href="javascript:parent.openapp('{:cmf_plugin_url($vo['name'].'://AdminIndex/index')}','plugin_{$vo.name}','{$vo.title}')"
                                       title="{:lang('Manage')}" data-toggle="tooltip">
                                        <i class="fa fa-window-maximize fa-fw"></i>
                                    </a>
                                    <else/>
                                    <a class="btn btn-xs btn-info disabled" href="javascript:;"
                                       title="{:lang('Manage')}" data-toggle="tooltip">
                                        <i class="fa fa-window-maximize fa-fw"></i>
                                    </a>
                                </if>
                                <span class="dropdown dropdown-hide-arrow" title="{:lang('Setting')}" data-toggle="tooltip">
                                    <span class="btn btn-primary btn-xs dropdown-toggle" data-bs-toggle="dropdown"
                                       role="button" aria-expanded="false1">
                                        <i class="fa fa-cog fa-fw"></i>
                                    </span>
                                    <ul class="dropdown-menu">
                                        <if condition="!empty($config)">
                                            <empty name="config.custom_config">
                                                <li>
                                                    <a class="dropdown-item"
                                                       data-href="{:url('Plugin/setting',array('id'=>$vo['id']))}"
                                                       href="javascript:;" onclick="openPluginSettingDialog(this)">
                                                        <i class="fa fa-cog fa-fw"></i> {:lang('Plugin Setting')}
                                                    </a>
                                                </li>
                                                <else/>
                                                <li>
                                                    <a class="dropdown-item"
                                                       data-href="{:cmf_plugin_url($vo['name'].'://AdminIndex/setting')}"
                                                       href="javascript:;" onclick="openPluginSettingDialog(this)">
                                                        <i class="fa fa-cog fa-fw"></i> {:lang('Plugin Setting')}
                                                    </a>
                                                </li>
                                            </empty>
                                        </if>
                                        <li>
                                            <a class="dropdown-item"
                                               data-href="{:url('admin/Plugin/hooks',['id'=>$vo.id])}"
                                               href="javascript:;" onclick="openPluginHooksDialog(this)">
                                                <i class="fa fa-sort-numeric-asc fa-fw"></i> {:lang('Execution order')}
                                            </a>
                                        </li>
                                    </ul>
                                </span>

                                <a class="btn btn-xs btn-success js-ajax-dialog-btn"
                                   href="javascript:void(0);"
                                   data-method="put"
                                   data-href="admin/plugins/{$vo.name}"
                                   data-msg="{:lang('UPDATE_PLUGIN_CONFIRM_MSG')}"
                                   title="{:lang('Update')}" data-toggle="tooltip">
                                    <i class="fa fa-refresh fa-fw"></i>
                                </a>

                                <if condition="$vo['status']==0">
                                    <a class="btn btn-xs btn-success js-ajax-dialog-btn"
                                       href="javascript:void(0);"
                                       data-href="admin/plugins/{$vo.id}/status/1"
                                       data-msg="{:lang('ENABLE_PLUGIN_CONFIRM_MSG')}"
                                       title="{:lang('Enable')}" data-toggle="tooltip">
                                        <i class="fa fa-toggle-on fa-fw"></i>
                                    </a>
                                    <else/>
                                    <a class="btn btn-xs btn-warning js-ajax-dialog-btn"
                                       href="javascript:void(0);"
                                       data-href="admin/plugins/{$vo.id}/status/0"
                                       data-msg="{:lang('Are you sure you want to disable this plugin?')}"
                                       title="{:lang('Disable')}" data-toggle="tooltip">
                                        <i class="fa fa-toggle-off fa-fw"></i></a>
                                </if>
                                <a class="btn btn-xs btn-danger js-ajax-delete"
                                   href="javascript:void(0);"
                                   data-href="admin/plugins/{$vo.id}"
                                   data-msg="{:lang('UNINSTALL_PLUGIN_CONFIRM_MSG')}"
                                   title="{:lang('Uninstall')}" data-toggle="tooltip">
                                    <i class="fa fa-trash fa-fw"></i></a>
                            </if>
                        </td>
                    </tr>
                </foreach>
                </tbody>
            </table>
        </form>
    </div>
</block>
<block name="scripts">
    <script>
        function openPluginSettingDialog(obj) {
            var $obj = $(obj);
            var href = $obj.data('href');
            parent.openIframeLayer(href, "{:lang('Plugin Setting')}", {
                area: GV.IS_MOBILE ? ['100%', '100%'] : ['95%', '95%'],
                offset: GV.IS_MOBILE ? ['0px', '0px'] : 'auto',
                // btn: ['确定', '取消'],
                yes: function (index, layero) {
                    console.log(layero);
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                    //iframeWin.confirm();
                    parent.layer.close(index); //如果设定了yes回调，需进行手工关闭
                },
                end: function () {
                }
            });
        }

        function openPluginHooksDialog(obj) {
            var $obj = $(obj);
            var href = $obj.data('href');
            parent.openIframeLayer(href, "{:lang('Plugin hooks')}", {
                area: GV.IS_MOBILE ? ['100%', '100%'] : ['95%', '95%'],
                offset: GV.IS_MOBILE ? ['0px', '0px'] : 'auto',
                // btn: ['确定', '取消'],
                yes: function (index, layero) {
                    console.log(layero);
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                    //iframeWin.confirm();
                    parent.layer.close(index); //如果设定了yes回调，需进行手工关闭
                },
                end: function () {
                }
            });
        }
    </script>
</block>
